package mapspinner.persistence.datatypes;

import java.io.IOException;
import java.io.Serializable;

import com.jme.util.export.InputCapsule;
import com.jme.util.export.JMEImporter;
import com.jme.util.export.OutputCapsule;
import com.jme.util.export.Savable;

public class TerrainSettings implements Savable, Serializable {
	private static final long serialVersionUID = 3505117732475576140L;

	private float horizontalScale = 3f;
	private float verticalScale = 1f;
	private int resolution = 65;
	private byte arrayWidth = 34;
	private float textureRepeat = 10f;
	private byte detailLevels = 5;
	private boolean modified = false;

	public byte getArrayWidth() {
		return arrayWidth;
	}

	public Class<? extends TerrainSettings> getClassTag() {
		return this.getClass();
	}

	public byte getDetailLevels() {
		return detailLevels;
	}

	public float getHorizontalScale() {
		return horizontalScale;
	}

	public int getResolution() {
		return resolution;
	}

	public float getTextureRepeat() {
		return textureRepeat;
	}

	public float getVerticalScale() {
		return verticalScale;
	}

	public boolean isModified() {
		return modified;
	}

	public void read(final JMEImporter im) throws IOException {
		final InputCapsule capsule = im.getCapsule(this);
		horizontalScale = capsule.readFloat("hm", 3f);
		verticalScale = capsule.readFloat("hm", 1f);
		resolution = capsule.readInt("res", 64 + 1);
		arrayWidth = capsule.readByte("aw", (byte) 34);
		textureRepeat = capsule.readFloat("tr", 10f);
		detailLevels = capsule.readByte("dl", (byte) 6);
	}

	public void setArrayWidth(final byte arrayWidth) {
		this.arrayWidth = arrayWidth;
		modified = true;
	}

	public void setDetailLevels(final byte detailLevels) {
		this.detailLevels = detailLevels;
		modified = true;
	}

	public void setHorizontalScale(final float horizontalScale) {
		this.horizontalScale = horizontalScale;
		modified = true;
	}

	public void setResolution(final int resolution) {
		this.resolution = resolution;
		modified = true;
	}

	public void setTextureRepeat(final float textureRepeat) {
		this.textureRepeat = textureRepeat;
		modified = true;
	}

	public void setVerticalScale(final float verticalScale) {
		this.verticalScale = verticalScale;
		modified = true;
	}

	public void write(final com.jme.util.export.JMEExporter ex)
			throws IOException {
		final OutputCapsule capsule = ex.getCapsule(this);
		capsule.write(horizontalScale, "hs", 3f);
		capsule.write(verticalScale, "vs", 1f);
		capsule.write(resolution, "res", 64 + 1);
		capsule.write(arrayWidth, "aw", (byte) 34);
		capsule.write(textureRepeat, "tr", 10f);
		capsule.write(detailLevels, "dl", (byte) 6);
	}

}
